package de.gwtprime.client.user;

import de.gwtprime.shared.requestFactory.User2Proxy;

public class ACLManager {

	
	public enum PrimeUIElement{
		EditProfile,
		QuestionDeleteBtn,
		QuestionEditBtn, // Add & Edit question
		ArticleSectionEdit,
		ArticleSectionDelete,
		ArticleSectionVoteUp,
		ArticleSectionVoteDown,
		ArticleSectionVoteComplete,
		ArticleSectionCompleteSection,
		AnswerAdd, // Add & Edit answer
		CommentDelete
	}
	
	/**
	 * Define what action provides how much karma
	 */
	public enum Karma{
		QuestionComplete(2l);
		
		private long karma;
		
		private Karma(long karma){
			this.karma = karma;
		}
		
		public long getKarma(){
			return karma;
		}
	}
	
	
	public static boolean hasUserAccess(User2Proxy user, PrimeUIElement access){
		if(user==null){
			return false;
		}
		
		// Article section can only be deleted by admin
		if(access == PrimeUIElement.ArticleSectionDelete && !user.isAdmin()){
			return false;
		}
		
		if(access == PrimeUIElement.QuestionDeleteBtn && !user.isAdmin()){
			return false;
		}
		
		if(access == PrimeUIElement.ArticleSectionEdit && !user.isAdmin()){
			return false;
		}
		
		if(true) // TODO for now diable acls
			return true;
		
		if(access==PrimeUIElement.ArticleSectionEdit 
				|| access == PrimeUIElement.ArticleSectionDelete
				|| access == PrimeUIElement.QuestionDeleteBtn
				|| access == PrimeUIElement.QuestionDeleteBtn){
			if(user.isAdmin()){
				return true;
			}else{
				return false;
			}
			
		}
		
		return true;
		
	}
	
}
